﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace WinnerCMS.Model
{
    [DataContractAttribute]
    public class zTreeNode
    {
        [DataMember]
        public string id { get; set; }
        [DataMember]
        public string pId { get; set; }
        [DataMember]
        public string name { get; set; }
        private string _title;
        [DataMember]
        public string title
        {
            get
            {
                if (_title == null)
                {
                    return this.name;
                }
                else
                {
                    return _title;
                }
            }
            set
            {
                _title = value;
            }
        }
        [DataMember]
        public string link { get; set; }

        public string _target;
        [DataMember]
        public string target
        {
            get
            {
                if (_target == null)
                {
                    return string.Empty;
                }
                else
                {
                    return _target;
                }
            }
            set
            {
                _target = value;
            }
        }
        [DataMember]
        public bool isParent { get; set; }
        [DataMember]
        public bool open { get; set; }

        public zTreeNode()
        {
            children = new List<zTreeNode>();
        }

        [DataMember]
        public IList<zTreeNode> children { get; set; }

        public static zTreeNode TozTreeNode(Memu mi)
        {
            if (mi == null)
            {
                throw new Exception("参数不完整。");
            }
            return new zTreeNode { id = mi.Id, name = mi.Title, pId = mi.Pid, link = mi.Link, open = mi.IsOpen };
        }
    }
}